package com.jerry.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * Created by Shirly on 2016/12/5.
 */
public class test {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        Class a = Class.forName("com.jerry.reflect.Peron");
        Class b = Peron.class;
        Peron peron = new Peron();
        Class c = peron.getClass();
        Object o1 = a.newInstance();
        if (o1 instanceof Peron) {
            Peron p = (Peron) o1;
            p.useTest();
        }
        Field[] field = a.getDeclaredFields();
        StringBuffer sb = new StringBuffer();
        sb.append(Modifier.toString(c.getModifiers()) + " class " + c.getSimpleName() + "{\n");
        for(Field f :field){
            sb.append("\t");//空格
            sb.append(Modifier.toString(f.getModifiers())+" ");//获取属性修饰符，如public static
            sb.append(f.getType().getSimpleName()+" ");//属性的名字
            sb.append(f.getName()+";\n");

        }
        sb.append("}");

        System.out.println(sb.toString());
    }

}


